package cn.jzq.kotoba.modules.designpattern.strategy.charge;

import cn.jzq.kotoba.modules.designpattern.strategy.charge.demo.Context;

/**
 * 网银充值，8.5折
 * 商户充值，9折
 * 手机充值，没有优惠
 * 点卡充值，收取1%的渠道费
 */
public class ChargeApp {

    public static void main(String[] args) {
        System.out.println(noobCalCharge(100.0, ChargeTypeEnum.E_BANK));

        Context context = new Context();
        // 网银充值100 需要付多少
        Double money = context.calRecharge(100.0, ChargeTypeEnum.E_BANK.getType());
        System.out.println(money);

        Double cardNeedPay = context.calRecharge(100.0, ChargeTypeEnum.CARD_CHARGE.getType());
        System.out.println(cardNeedPay);
    }

    /**
     * 四种计算方式都在一个方法内部，如果优惠模式又增加了几十种，代码会变成变得十分臃肿和难以维护
     * @param charge
     * @param type
     * @return
     */
    public static Double noobCalCharge(Double charge, ChargeTypeEnum type ) {
        if (ChargeTypeEnum.E_BANK.equals(type)) {
            return charge * 0.85;
        } else if (ChargeTypeEnum.USER_ACCOUNT.equals(type)) {
            return charge * 0.9;
        } else if (ChargeTypeEnum.MOBILE.equals(type)) {
            return charge ;
        } else if (ChargeTypeEnum.CARD_CHARGE.equals(type)) {
            return charge + charge * 0.01;
        }
        return 0.0;
    }
}
